//package com.chetubao.controller;
//
//import com.payment.entity.Account;
//import com.payment.service.AccountService;
//import com.chetubao.util.TokenUtil;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.solar.bean.JsonResult;
//import org.solar.cache.Cache;
//import org.solar.coder.Md5Util;
//import org.solar.util.Assert;
//import org.solar.util.StringUtil;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//
//@Controller
//public class RegisterController {
//    private static final Logger logger = LoggerFactory.getLogger(RegisterController.class);
//    @Resource
//    private AccountService accountService;
//
//    @RequestMapping("register")
//    @ResponseBody
//    public JsonResult register(HttpServletRequest req,Account account, String mobileNo, String mobileCode, String password) throws Exception {
//        String captcha= Cache.getDefaultCache().get("mobileNoCode:"+mobileNo);
//        if (captcha==null){
//            return JsonResult.error("请先获取验证码!");
//        }
//        if (!captcha.equalsIgnoreCase(mobileCode)){
//            return JsonResult.error("验证码错误!");
//        };
//        Account accountDB=accountService.selectOneByWhere("mobileNo",mobileNo);
//        if (accountDB!=null){
//            //如果数据库已有该手机号   则直接返回
//            return new JsonResult(201,"该手机已经注册了!",accountDB);
//        }
//        if (account.getRole()!=null&&account.getRole()==1){
//            return JsonResult.error("管理员不能注册!");
//        }
//        String aId=TokenUtil.getTokenId(req);
//        if (StringUtil.isNotEmpty(aId)){
//                accountDB=accountService.getById(aId);
//            if (accountDB!=null){
//                account.setWechatOpenId(accountDB.getWechatOpenId());
//                account.setAlipayUserId(accountDB.getAlipayUserId());
//            }
//        }
//        account.setPassword(Md5Util.getMd5Hex(password));
//        accountService.save(account);
//        return JsonResult.success(account);
//    }
//
//    @RequestMapping("resetPassword")
//    @ResponseBody
//    public JsonResult resetPassword(String mobileNo, String mobileCode, String password) throws Exception {
//        Assert.notEmpty(mobileNo);
//        Account account=accountService.selectOneByWhere("mobileNo",mobileNo);
//        if (account==null){
//            return JsonResult.error("没有该账号!");
//        }
//        String captcha= Cache.getDefaultCache().get("mobileNoCode:"+mobileNo);
//        if (captcha==null){
//            return JsonResult.error("请先获取验证码!");
//        }
//        if (!captcha.equalsIgnoreCase(mobileCode)){
//            return JsonResult.error("验证码错误!");
//        };
//        account.setPassword(Md5Util.getMd5Hex(password));
//        accountService.updateByPrimaryKey(account);
//        return JsonResult.success();
//    }
//}
